package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.core.domain.entity.SysPropertyComment;
import com.ruoyi.system.mapper.SysCommentMapper;
import com.ruoyi.common.core.domain.entity.SysComment;
import com.ruoyi.system.service.ISysCommentService;

/**
 * 评论详情Service业务层处理
 * 
 * @author ssd
 * @date 2024-03-29
 */
@Service
public class SysCommentServiceImpl implements ISysCommentService 
{
    @Autowired
    private SysCommentMapper sysCommentMapper;

    /**
     * 查询评论详情
     * 
     * @param commentId 评论详情主键
     * @return 评论详情
     */
    @Override
    public SysComment selectSysCommentByCommentId(Long commentId)
    {
        return sysCommentMapper.selectSysCommentByCommentId(commentId);
    }

    /**
     * 查询评论详情列表
     * 
     * @param sysComment 评论详情
     * @return 评论详情
     */
    @Override
    public List<SysComment> selectSysCommentList(SysComment sysComment)
    {
        return sysCommentMapper.selectSysCommentList(sysComment);
    }

    /**
     * 新增评论详情
     * 
     * @param sysComment 评论详情
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysComment(SysComment sysComment)
    {
        int rows = sysCommentMapper.insertSysComment(sysComment);
        insertSysPropertyComment(sysComment);
        return rows;
    }

    /**
     * 修改评论详情
     * 
     * @param sysComment 评论详情
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysComment(SysComment sysComment)
    {
        sysCommentMapper.deleteSysPropertyCommentByCommentId(sysComment.getCommentId());
        insertSysPropertyComment(sysComment);
        return sysCommentMapper.updateSysComment(sysComment);
    }

    /**
     * 批量删除评论详情
     * 
     * @param commentIds 需要删除的评论详情主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysCommentByCommentIds(Long[] commentIds)
    {
        sysCommentMapper.deleteSysPropertyCommentByCommentIds(commentIds);
        return sysCommentMapper.deleteSysCommentByCommentIds(commentIds);
    }

    /**
     * 删除评论详情信息
     * 
     * @param commentId 评论详情主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysCommentByCommentId(Long commentId)
    {
        sysCommentMapper.deleteSysPropertyCommentByCommentId(commentId);
        return sysCommentMapper.deleteSysCommentByCommentId(commentId);
    }

    /**
     * 新增房源评论id关联表信息
     * 
     * @param sysComment 评论详情对象
     */
    public void insertSysPropertyComment(SysComment sysComment)
    {
        List<SysPropertyComment> sysPropertyCommentList = sysComment.getSysPropertyCommentList();
        Long commentId = sysComment.getCommentId();
        if (StringUtils.isNotNull(sysPropertyCommentList))
        {
            List<SysPropertyComment> list = new ArrayList<SysPropertyComment>();
            for (SysPropertyComment sysPropertyComment : sysPropertyCommentList)
            {
                sysPropertyComment.setCommentId(commentId);
                list.add(sysPropertyComment);
            }
            if (list.size() > 0)
            {
                sysCommentMapper.batchSysPropertyComment(list);
            }
        }
    }
}
